<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex flex-direction flex-wrap align-stretch benben-position-layout flex businessContent_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub businessContent_fd0_0'>
          <view class='flex flex-wrap align-center businessContent_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  businessContent_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='businessContent_fd0_0_c1_c0'>智能找粮</text>
          </view>
          <view class='flex flex-wrap align-center justify-end businessContent_fd0_0_c0'>
            <image class='businessContent_fd0_0_c2_c0' mode="aspectFit" :src='STATIC_URL+"7.png"'></image>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
        <view class='flex flex-wrap align-center businessContent_fd1_0'>
          <text class='businessContent_fd1_0_c0'>我经营的内容</text>
          <text class='businessContent_fd1_0_c1'>如实填写才能更好的展示，可多选。</text>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout businessContent_flex_2">
        <view class='flex flex-direction flex-wrap align-stretch businessContent_fd2_0' v-for="(item,index) in list"
          :key="index">
          <view class='flex flex-wrap align-center justify-between businessContent_fd2_0_c0'>
            <text class='businessContent_fd2_0_c0_c0'>{{item.mingcheng}}</text>
            <view class='flex flex-wrap align-center' v-if="item.children.length>3" @click="open(item)">
              <text class='businessContent_fd2_0_c0_c1_c0'>{{item.is_check ? '收起' : '展开'}}</text>
              <image class='businessContent_fd2_0_c0_c1_c1' mode="aspectFit" :src='STATIC_URL+"133.png"'></image>
            </view>
          </view>
          <view class='flex flex-wrap align-center'>
            <view class="" v-for='(itemC,key0) in item.children' v-if="key0<3 && !item.is_check">
              <view v-if="itemC.is_check" class='flex align-center justify-center flex businessContent_fd2_0_c1_c0_c0'
                :key="key0" @tap.stop="closePopup(item,itemC,key0)">
                <text class='businessContent_fd2_0_c1_c0_c0_c0'>{{itemC.mingcheng}}</text>
                <image class='businessContent_fd2_0_c1_c0_c0_c1' mode="aspectFit" :src='STATIC_URL+"131.png"'></image>
              </view>
              <view v-else class='flex align-center justify-center flex businessContent_fd2_0_c1_c0_c1' :key="key0"
                @tap.stop="closePopup(item,itemC,key0)">
                <text class='businessContent_fd2_0_c1_c0_c1_c0'>{{itemC.mingcheng}}</text>
              </view>
            </view>
            <view class="" v-for='(itemC,key0) in item.children' v-if="item.is_check">
              <view v-if="itemC.is_check" class='flex align-center justify-center flex businessContent_fd2_0_c1_c0_c0'
                :key="key0" @tap.stop="closePopup(item,itemC,key0)">
                <text class='businessContent_fd2_0_c1_c0_c0_c0'>{{itemC.mingcheng}}</text>
                <image class='businessContent_fd2_0_c1_c0_c0_c1' mode="aspectFit" :src='STATIC_URL+"131.png"'></image>
              </view>
              <view v-else class='flex align-center justify-center flex businessContent_fd2_0_c1_c0_c1' :key="key0"
                @tap.stop="closePopup(item,itemC,key0)">
                <text class='businessContent_fd2_0_c1_c0_c1_c0'>{{itemC.mingcheng}}</text>
              </view>
            </view>
          </view>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-wrap align-center justify-center benben-flex-layout businessContent_flex_3">
        <button class='businessContent_fd3_0' @tap.stop="submit" data-type="redirectTo"
          :data-url="`/pages/wode/managemyDevice/managemyDevice`">确定</button>
      </view>

      <!---flex布局flex布局结束-->


    </view>
  </view>
</template>
<script>
  export default {
    components: {},


    data() {
      return {
        list: [],
        "aid": "",
        ids: [],
        lat: '',
        lng: '',
        type: '',
        liangzhancate_id: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        aid,
        lat,
        lng,
        type,
        liangzhancate_id
      } = options
      if (aid !== undefined) this.aid = aid
      if (lat !== undefined) this.lat = lat
      if (lng !== undefined) this.lng = lng
      if (type !== undefined) this.type = type
      if (liangzhancate_id !== undefined) this.liangzhancate_id = liangzhancate_id
      this.getttype()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      open(item) {
        item.is_check = !item.is_check
      },
      closePopup(item, itemC, key0) {
        itemC.is_check = !itemC.is_check
        console.log('key0', key0)
        if (itemC.is_check) {
          let obj = {
            bigId: item.aid,
            aid: itemC.aid,
            name: itemC.mingcheng
          }
          this.ids.push(obj)
        } else {
          if (this.ids.length == 1) {
            this.ids = []
          } else {
            this.ids.splice(key0, 1)
          }

          // console.log(';;key0', itemC.is_check)
          // console.log(';;2222222', itemC.is_check)
          // console.log(';;2222222', this.ids)
        }

      },
      submit() {
        let liangzhancate_id = ''
        let objs = ''
        if (this.ids.length) {
          liangzhancate_id = this.ids.map(item => {
            return item.aid
          }).join(',')
          objs = {
            jingdu: this.lng,
            weidu: this.lat,
            liangzhancate_id: liangzhancate_id
          }
        }
        if (this.type == 1) {

          uni.$emit('liangzhancate_arr', this.ids)
          uni.navigateBack()
        } else {
          uni.redirectTo({
            url: `/pages/wode/managemyDevice/managemyDevice?objs=${JSON.stringify(objs)}`
          })
        }

        // /pages/wode/managingpersonalInformation/managingpersonalInformation

      },
      getttype() {
        this.$api.post(global.apiUrls.post65d83a0a31e1a, {
          ids: this.liangzhancate_id
        }).then(res => {
          if (res.data.code == 1) {
            this.list = res.data.data
            for (let i = 0; i < this.list.length; i++) {
              for (let j = 0; j < this.list[i].children.length; j++) {

                if (this.list[i].children[j].is_check) {
                  let objs = {
                    aid: this.list[i].children[j].aid,
                    bigId: this.list[i].aid,
                    name: this.list[i].children[j].mingcheng
                  }
                  this.ids.push(objs)
                }
              }
            }
            console.log('1s', this.ids)
          }
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(248, 248, 250, 1);
    background-size: 100% auto;
  }

  .businessContent_flex_0 {
    background: rgba(255, 255, 255, 1);
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto;
  }

  .businessContent_fd0_0_c2_c0 {
    width: 119rpx;
    height: 55rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .businessContent_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .businessContent_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .businessContent_fd0_0_c0 {
    width: 120rpx;
  }

  .businessContent_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .businessContent_fd1_0_c1 {
    color: #BFBFBF;
    font-size: 26rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .businessContent_fd1_0_c0 {
    color: #333333;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 42rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .businessContent_fd1_0 {
    padding: 32rpx;
  }

  .businessContent_flex_2 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .businessContent_fd2_0_c1_c0_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .businessContent_fd2_0_c1_c0_c1 {
    background: rgba(245, 245, 245, 1);
    margin: 24rpx 15rpx 0rpx 0rpx;
    padding: 14rpx 44rpx 14rpx 44rpx;
    border-radius: 6rpx;
    background-size: 100% auto;
    width: 200rpx;
  }

  .businessContent_fd2_0_c1_c0_c0_c1 {
    width: 32rpx;
    height: 32rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    position: absolute;
    right: 0rpx;
    bottom: 0rpx;
  }

  .businessContent_fd2_0_c1_c0_c0_c0 {
    color: #2568AE;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .businessContent_fd2_0_c1_c0_c0 {
    background: rgba(37, 104, 174, 0.2);
    padding: 14rpx 44rpx 14rpx 44rpx;
    width: 200rpx;
    border-radius: 6rpx;
    background-size: 100% auto;
    margin: 24rpx 15rpx 0rpx 0rpx;
    position: relative;
  }

  .businessContent_fd2_0_c0_c1_c1 {
    width: 20rpx;
    height: 10rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx 16rpx;
  }

  .businessContent_fd2_0_c0_c1_c0 {
    color: #333333;
    font-size: 24rpx;
    font-weight: 400;
    line-height: 42rpx;
  }

  .businessContent_fd2_0_c0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 700;
    line-height: 32rpx;
  }

  .businessContent_fd2_0_c0 {
    margin: 0rpx 22rpx 0rpx 0rpx;
  }

  .businessContent_fd2_0 {
    background: rgba(255, 255, 255, 1);
    border-radius: 16rpx;
    background-size: 100% auto;
    margin: 0rpx 0rpx 24rpx 0rpx;
    padding: 32rpx 0rpx 32rpx 24rpx;
  }

  .businessContent_flex_3 {
    margin: 16rpx 0rpx 0rpx 0rpx;
  }

  .businessContent_fd3_0 {
    background: rgba(37, 104, 174, 1);
    border-radius: 50rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 34rpx;
    color: #fff;
  }
</style>
